package com.atguigu.tingshu.user.rpc;

import com.atguigu.tingshu.common.login.annotation.TingshuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.user.VipServiceConfig;
import com.atguigu.tingshu.user.service.UserInfoService;
import com.atguigu.tingshu.user.service.VipServiceConfigService;
import com.atguigu.tingshu.vo.user.UserInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * ClassName: UserInfoRpcController
 * Package: com.atguigu.tingshu.user.rpc
 * Description:
 *
 * @Author 梅超凡
 * @Create 2025/1/20 19:09
 * @Version 1.0
 */

@RequestMapping("/api/rpc/userInfo")
@RestController
public class UserInfoRpcController {

    @Autowired
    private UserInfoService userInfoService;


    @Autowired
    private VipServiceConfigService vipServiceConfigService;

    @GetMapping("/getUserInfo/{userId}")
    @Operation(summary = "获取登录用户信息")
//    @TingshuLogin
    public Result<UserInfoVo> getUserInfoId(@PathVariable(value = "userId") Long userId) {
        UserInfoVo userInfoVo = userInfoService.getUserInfo(userId);
        return Result.ok(userInfoVo);
    }

    @GetMapping(value = "/getUserPaidAlbumTrackList/{userId}/{albumId}")
    @Operation(summary = "查询登录用户是否买过专辑下的声音列表")
    Result<Map<Long, String>> getUserPaidAlbumTrackList(@PathVariable(value = "userId") Long userId, @PathVariable(value = "albumId") Long albumId) {

        Map<Long, String> map = userInfoService.getUserPaidAlbumTrackList(userId, albumId);
        return Result.ok(map);
    }


    @GetMapping(value = "/getUserPaidAlbum/{userId}/{albumId}")
    Result<Boolean> getUserPaidAlbum(@PathVariable(value = "userId") Long userId, @PathVariable(value = "albumId") Long albumId) {
        Boolean isPaid = userInfoService.getUserPaidAlbum(userId, albumId);
        return Result.ok(isPaid);
    }

    @GetMapping(value = "/getAllVipConfig/{itemId}")
    @Operation(summary = "获取用户微服务获取vip套餐")
    @Parameters({
            @Parameter(name = "itemId", description = "套餐id", required = true)
    })
    Result<VipServiceConfig> getAllVipConfig(@PathVariable(value = "itemId") Long itemId) {
        VipServiceConfig vipServiceConfig = vipServiceConfigService.getById(itemId);
        return Result.ok(vipServiceConfig);
    }
}
